import React, { useEffect, useState } from 'react'
import { View, Image, Text } from '@tarojs/components'
import { ArrowLeft } from '@nutui/icons-react-taro'
import Taro from '@tarojs/taro'
import './AppHeader.scss'

export default function AppHeader(props) {
    // 标题
    const { title, top ,bar } = props
    const [systemHeight, setSystemHeight] = useState(0)

    // 获取手机状态栏高度
    const getSystemHeight = async () => {
        const height = await Taro.getSystemInfo()
        setSystemHeight(height.statusBarHeight)
    }
    const toBack = () => {
        Taro.navigateBack({
            delta: 1
        })
    }

    useEffect(() => {
        getSystemHeight()
    }, [])

    return (
        <>
            {top ?
                <View className='app-header header-top' style={{ paddingTop: systemHeight }}>
                    {!bar?<Text className='iconfont icon-saoyisao icon' onClick={toBack}></Text>:''}
                    {title}
                </View> : <View className='app-header' style={{ paddingTop: systemHeight }}>
                    <Text className='iconfont icon-saoyisao'></Text>
                    {title}
                </View>}
        </>
    )
}
